home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / Common / ZStackCrawl.h < prev    next >
Text File  |  1997-07-27  |  2KB  |  95 lines

  1. /*
  2.  *  File:       ZStackCrawl.h
  3.  *  Summary:       Stack crawl class based on the class in the OpenDoc utilities.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     7/28/97    JDJ        Added pragma once.
  12.  *         <1>     2/02/97    JDJ        Created.
  13.  */
  14.  
  15. #pragma once
  16.  
  17. #include <stddef.h>
  18.  
  19. #include <ZTypes.h>
  20.  
  21.  
  22. //-----------------------------------
  23. //    Forward References
  24. //
  25. class StackID;
  26.  
  27.  
  28. //-----------------------------------
  29. //    Types
  30. //
  31. typedef const StackID* StackFrameID;    // magic cookie
  32.  
  33.  
  34. // ===================================================================================
  35. //    struct SStackFrame
  36. // ===================================================================================
  37. struct SStackFrame {
  38.     string            name;            // name of the function
  39.     const void*        start;            // pointer to the start of the function
  40.     size_t            offset;            // offset from the start of the function to the PC
  41.     bool            native;            // true if function is PPC code
  42. };
  43.  
  44.  
  45. // ===================================================================================
  46. //    class TStackCrawl
  47. // ===================================================================================
  48. class TStackCrawl {
  49.  
  50.     enum {kMaxFrames = 32};
  51.  
  52. //-----------------------------------
  53. //    Initialization/Destruction
  54. //
  55. public:
  56.                         ~TStackCrawl();
  57.  
  58.                         TStackCrawl(ulong startFrame = 0, ulong numFrames = kMaxFrames);
  59.                         // Frame numbers start at 0 which is the caller of the TStackCrawl 
  60.                         // constructor and work upwards to the base of the stack.
  61.                 
  62. //-----------------------------------
  63. //    API
  64. //
  65. public:
  66.             ulong         GetNumFrames() const                    {return mNumFrames;}
  67.             
  68.             SStackFrame GetFrame(ulong frame) const;
  69.             
  70.             StackFrameID GetID(ulong frame) const;
  71.                         // Returns an identifier (or cookie) that can be used later to 
  72.                         // generate the stack frame.
  73.             
  74.     static    SStackFrame GetFrame(StackFrameID id);
  75.     
  76.     static     SStackFrame GetCaller();
  77.                         // Returns the stack frame of the function that called the
  78.                         // function that called GetCaller.
  79.                         
  80. //-----------------------------------
  81. //    Internal API
  82. //
  83. protected:
  84.     static     SStackFrame GetFrame(size_t pc, bool native);
  85.  
  86. //-----------------------------------
  87. //    Member Data
  88. //
  89. protected:
  90.     ulong          mNumFrames;
  91.     const void*    mFrame[kMaxFrames];        // frames starting at startFrame
  92. };
  93.  
  94.  
  95.